using System;

using Elev.Core.DAL;

namespace Elev.Core
{
    internal enum AvailableKeys
    {
        DBVERSION,
        CLASSNAME,
        CLASSDESCRIPTION,
        SELECTEDSTUDENT,
        SELECTEDPERIOD
    }

    static public class MetaInfo
    {
        static int dBVersion = -1;
        static public int DBVersion
        {
            get
            {
                if (dBVersion == -1)
                    dBVersion = Convert.ToInt32(GetValue(AvailableKeys.DBVERSION));
                
                return dBVersion;
            }
            set
            {
                dBVersion = value;
                SetValue(AvailableKeys.DBVERSION, dBVersion);
            }
        }

        static string className = string.Empty;
        static public string ClassName
        {
            get
            {
                if (className == "")
                    className = (string)GetValue(AvailableKeys.CLASSNAME);

                return className;
            }
            set
            {
                className = value;
                SetValue(AvailableKeys.CLASSNAME, className);
            }
        }

        static string classDescription = string.Empty;
        static public string ClassDescription
        {
            get
            {
                if (classDescription == "")
                    classDescription = (string)GetValue(AvailableKeys.CLASSDESCRIPTION);

                return classDescription;
            }
            set
            {
                classDescription = value;
                SetValue(AvailableKeys.CLASSDESCRIPTION, classDescription);
            }
        }

        static int selectedStudent = -1;
        static public int SelectedStudent
        {
            get
            {
                if (selectedStudent == -1)
                    selectedStudent = Convert.ToInt32(GetValue(AvailableKeys.SELECTEDSTUDENT));

                return selectedStudent;
            }
            set
            {
                selectedStudent = value;
                SetValue(AvailableKeys.SELECTEDSTUDENT, selectedStudent);
            }
        }

        static int selectedPeriod = -1;
        static public int SelectedPeriod
        {
            get
            {
                if (selectedPeriod == -1)
                    selectedPeriod = Convert.ToInt32(GetValue(AvailableKeys.SELECTEDPERIOD));

                return selectedPeriod;
            }
            set
            {
                selectedPeriod = value;
                SetValue(AvailableKeys.SELECTEDPERIOD, selectedPeriod);
            }
        }

        static public void Clear()
        {
            className = "";
            classDescription = "";
            selectedStudent = -1;
            selectedPeriod = -1;
        }

        // Constants
        static public Type GradeType
        {
            get { return typeof(double); }
        }

        static public double MinGradeValue
        {
            get { return 0.0; }
        }

        static public double MaxGradeValue
        {
            get { return 20.0; }
        }

        #region Private Members

        static object GetValue(AvailableKeys Key)
        {
            MetaInfoInternal miInternal = new MetaInfoInternal();
            return miInternal.GetValue(Key.ToString());
        }

        static void SetValue(AvailableKeys Key, object Value)
        {
            MetaInfoInternal miInternal = new MetaInfoInternal();
            miInternal.SetValue(Key.ToString(), Value.ToString());
        }

        #endregion
    }
}
